package com.dhy.socket.handler;

import com.dhy.calculate.Calculator;
import com.dhy.handle.FileHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;


/**
 * @author 大忽悠
 * @create 2022/7/5 10:16
 */
@Slf4j
public class DistributeClientInfoHandler extends ChannelInboundHandlerAdapter {
    /**
     * 计算数据
     */
    private static final Calculator cal=new Calculator();
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        try {
            String indexInfo = (String) msg;
            log.info("接收到来自主实例的index分片信息: {}",indexInfo);
            //返回当前分片数据
            cal.setLineItemIndexData(FileHandler.readByIndex(indexInfo));
            ctx.fireChannelRead(msg);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void channelWrite(Channel channel){
      //  channel.writeAndFlush("hhh");
    }
}
